package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-07-07
 * Time: 22:12
 */
public class ReturnOperation implements IOperation{
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要归还的图书的名字：");
        String name = scanner.nextLine();
        int sz = bookList.getBookSize();   //获取当前书架上图书的数量
        for (int i = 0 ;i < sz ;i++) {
            if(name.equals(bookList.getBook(i).getName())) {   //通过equals方法进行名字比较
                Book book = bookList.getBook(i);
                System.out.println("归还成功！");
                book.setBorrowed(false);
                return;
            }
            System.out.println("没有你要归还的书。少年，你怕是走错图书馆了！");   //未找到执行
            return;
        }
    }
}
